Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-date-picker

Package Overview
Dependencies
Maintainers
1
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-date-picker

A date picker for your React app.

  • 8.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
220K
decreased by-6.79%
Maintainers
1
Weekly downloads
 
Created

What is react-date-picker?

The react-date-picker package is a flexible and customizable date picker component for React applications. It allows users to select dates from a calendar interface and provides various customization options to fit different use cases.

What are react-date-picker's main functionalities?

Basic Date Picker

This code demonstrates a basic usage of the react-date-picker component. It initializes a date state and renders a DatePicker component that allows the user to select a date.

import React, { useState } from 'react';
import DatePicker from 'react-date-picker';

function MyApp() {
  const [date, setDate] = useState(new Date());

  return (
    <div>
      <DatePicker
        onChange={setDate}
        value={date}
      />
    </div>
  );
}

export default MyApp;

Date Range Picker

This code demonstrates how to use react-date-picker to select a date range by using two DatePicker components, one for the start date and one for the end date.

import React, { useState } from 'react';
import DatePicker from 'react-date-picker';

function MyApp() {
  const [startDate, setStartDate] = useState(new Date());
  const [endDate, setEndDate] = useState(new Date());

  return (
    <div>
      <DatePicker
        onChange={setStartDate}
        value={startDate}
      />
      <DatePicker
        onChange={setEndDate}
        value={endDate}
      />
    </div>
  );
}

export default MyApp;

Custom Date Format

This code demonstrates how to customize the date format displayed in the react-date-picker component. The 'format' prop is used to specify the desired date format.

import React, { useState } from 'react';
import DatePicker from 'react-date-picker';

function MyApp() {
  const [date, setDate] = useState(new Date());

  return (
    <div>
      <DatePicker
        onChange={setDate}
        value={date}
        format="y-MM-dd"
      />
    </div>
  );
}

export default MyApp;

Disable Specific Dates

This code demonstrates how to disable specific dates in the react-date-picker component. The 'tileDisabled' prop is used to specify which dates should be disabled.

import React, { useState } from 'react';
import DatePicker from 'react-date-picker';

function MyApp() {
  const [date, setDate] = useState(new Date());

  const disableDates = [
    new Date(2023, 9, 10),
    new Date(2023, 9, 15)
  ];

  return (
    <div>
      <DatePicker
        onChange={setDate}
        value={date}
        tileDisabled={({ date }) => disableDates.some(disabledDate => date.getTime() === disabledDate.getTime())}
      />
    </div>
  );
}

export default MyApp;

Other packages similar to react-date-picker

Keywords

FAQs

Package last updated on 04 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc